//---------------------------------------------------------------------------
// CWebShell
// Author : Woo-Hyun Kim
// Email : woorung@icu.ac.kr
// Date : Jul. 7, 2006
//---------------------------------------------------------------------------
#include "CWebShell.h"

CWebShell::CWebShell() : CProcess()
{
	command = "";
}

CWebShell::CWebShell(string &comm) : CProcess()
{
	command = comm;
}

CWebShell::CWebShell(int verbose) : CProcess(verbose)
{
	command = "";
}

CWebShell::CWebShell(string &comm, int verbose) : CProcess(verbose)
{
	command = comm;
}

CWebShell::~CWebShell() 
{
}

int CWebShell::read_upstream(const char *buf) 
{
	size_t size = strlen(buf);

	for(size_t i=0;i<size;i++) {
		if(*((char*)buf+i)=='\n') cout << "<br>" << endl;
		else cout << *((char *)buf + i);
	}

	return 1;
}

int CWebShell::read_upstream(const void *buf, size_t size) 
{
	for(size_t i=0;i<size;i++) {
		if(*((char*)buf+i)=='\n') cout << "<br>" << endl;
		else cout << *((char *)buf + i);
	}

	return 1;
}

int CWebShell::read_downstream(const char *buf) 
{
}

int CWebShell::read_downstream(const void *buf, size_t size) 
{
}

int CWebShell::read_errstream(const char *buf) 
{
	size_t size = strlen(buf);

	for(size_t i=0;i<size;i++) {
		if(*((char*)buf+i)=='\n') cerr << "<br>" << endl;
		else cerr << *((char *)buf + i);
	}

	return 1;
}

int CWebShell::read_errstream(const void *buf, size_t size) 
{
	for(size_t i=0;i<size;i++) {
		if(*((char*)buf+i)=='\n') cerr << "<br>" << endl;
		else cerr << *((char *)buf + i);
	}

	return 1;
}

void CWebShell::set(string &comm) 
{ 
	command = comm;
}

string &CWebShell::get() 
{ 
	return command; 
}

void CWebShell::before_run() 
{
	//write_downstream("woorung nara\n");
};

void CWebShell::run() 
{
	system((char *)command.c_str());
}
